home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1461.dms / var1461.adf / IncludeFonts / Example.c < prev    next >
C/C++ Source or Header  |  1992-05-07  |  5KB  |  167 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Graphics                Amiga C Club       */
  7. /* Chapter: Include Fonts               Tulevagen 22       */
  8. /* File:    Example.c                   181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20.  
  21. /* This is an example on how you can "include" a font in your  */
  22. /* 'C' code. See file "PrintFont.c" for more information.      */
  23. /*                                                             */
  24. /* This example consists of two files which should be compiled */
  25. /* separately and then linked together. The first file is this */
  26. /* one, and consists of the program code itself. The second    */
  27. /* file is called "FontFile.c" and was created by PrintFont,   */
  28. /* and contains all information about the font.                */
  29.  
  30.  
  31. /* Include all Intuition declarations: */
  32. #include <intuition/intuition.h>
  33.  
  34.  
  35.  
  36.  
  37.  
  38. /* Note that you do not need to open the DiskFont Library in this   */
  39. /* example. It is only when you try to load a new font the library  */
  40. /* has to be open.                                                  */
  41.  
  42. struct Intuition *IntuitionBase = NULL; /* Running under Intuition. */
  43. struct GfxBase *GfxBase = NULL;         /* Move() and Text().       */
  44.  
  45.  
  46. /* Declare a pointer to a Window structure: */ 
  47. struct Window *my_window = NULL;
  48.  
  49. /* Declare and initialize your NewWindow structure: */
  50. struct NewWindow my_new_window=
  51. {
  52.   0,             /* LeftEdge    x position of the window. */
  53.   20,            /* TopEdge     y positio of the window. */
  54.   450,           /* Width       450 pixels wide. */
  55.   55,            /* Height      55 lines high. */
  56.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  57.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  58.   NULL,          /* IDCMPFlags  No IDCMP flags */
  59.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  60.   WINDOWDRAG|    /*             Drag gadget. */
  61.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  62.   ACTIVATE,      /*             The window should be Active when opened. */
  63.   NULL,          /* FirstGadget No Custom gadgets. */
  64.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  65.   "IncludeFonts V1.0  Anders Bjerin  Amiga C Club", /* Title */
  66.   NULL,          /* Screen      Connected to the Workbench Screen. */
  67.   NULL,          /* BitMap      No Custom BitMap. */
  68.   0,             /* MinWidth    No sizing gadget. */
  69.   0,             /* MinHeight          -"-        */
  70.   0,             /* MaxWidth           -"-        */
  71.   0,             /* MaxHeight          -"-        */
  72.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  73. };
  74.  
  75.  
  76.  
  77. /* The text font structure which is defined */
  78. /* in the other file ("FontFile"):          */
  79. extern struct TextFont NewsletterFont;
  80.  
  81.  
  82.  
  83. /* Declare our functions: */
  84. void main( );
  85. void clean_up( STRPTR );
  86.  
  87.  
  88.  
  89. void main( )
  90. {
  91.   /* Open the necessary libraries: */
  92.  
  93.   /* Open the Intuition Library: */
  94.   IntuitionBase = (struct IntuitionBase *)
  95.     OpenLibrary( "intuition.library", 0 );
  96.   if( !IntuitionBase )
  97.     clean_up( "Could not open Intuition library!" );
  98.  
  99.   /* Open the Graphics library: */
  100.   GfxBase = (struct GfxBase *)
  101.     OpenLibrary( "graphics.library", 0 );
  102.   if( !GfxBase )
  103.     clean_up( "Could not open Graphics library!" );
  104.  
  105.  
  106.  
  107.  
  108.  
  109.   /* Open a window in which we will display the new font: */
  110.   my_window = (struct Window *) OpenWindow( &my_new_window );
  111.   
  112.   /* Have we opened the window succesfully? */
  113.   if(my_window == NULL)
  114.     clean_up( "Could not open the window!" );
  115.  
  116.  
  117.  
  118.   /* Set colour and draw mode: */
  119.   SetAPen( my_window->RPort, 1 );
  120.   SetDrMd( my_window->RPort, JAM1 );
  121.  
  122.  
  123.   /* This is the only thing you have to do */
  124.   /* once you have converted the font!     */
  125.   /* Change the window's default font:     */
  126.   SetFont( my_window->RPort, &NewsletterFont );
  127.  
  128.  
  129.   /* Position the cursor, and print some characters: */
  130.   Move( my_window->RPort, 10, 38 );
  131.   Text( my_window->RPort, "This font is great!", 22 );
  132.  
  133.  
  134.   /* Wait 5 seconds: */
  135.   Delay( 50 * 5 );
  136.  
  137.  
  138.  
  139.   /* The End: */
  140.   clean_up( "" );
  141. }
  142.  
  143.  
  144.  
  145. /* Clears and quits: */
  146. void clean_up( STRPTR message )
  147. {
  148.   /* Close the window: */
  149.   if( my_window )
  150.     CloseWindow( my_window );
  151.  
  152.   /* Close the Graphics Library: */
  153.   if( GfxBase )
  154.     CloseLibrary( GfxBase );
  155.  
  156.   /* Close the IntuitionLibrary: */
  157.   if( IntuitionBase )
  158.     CloseLibrary( IntuitionBase );
  159.   
  160.   /* Print any message: */
  161.   printf( "%s\n", message );
  162.  
  163.   /* Quit: */
  164.   exit();
  165. }
  166.  
  167.